﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KCMS.BusinessLogic.Interfaces;
using StructureMap;
using KCMS.BusinessLogic.Models;

namespace KCMS.BusinessLogic.Engine
{
    public class FilterProduct:IFilterProduct
    {
        public IEnumerable<Models.Product> getAll(IEnumerable<Product> source,int filter)
        {
            switch (filter)
            {
                case 1:
                    return getByArticleAscending(source);
                    break;
                case 2:
                    return getByArticleDescending(source);
                    break;
                case 3:
                    return getByPriceAscending(source);
                    break;
                case 4:
                    return getByPriceDescending(source);
                    break;
                case 5:
                    return getByDateAscending(source);
                    break;
                case 6:
                    return getByDateDescending(source);
                    break;
                default:
                    return source;
            }
        }
        private IEnumerable<Models.Product> getByArticleAscending(IEnumerable<Product> source)
        {
            return (from t in source
                    orderby t.Article ascending
                    select t).ToList();
        }
        private IEnumerable<Models.Product> getByArticleDescending(IEnumerable<Product> source)
        {
            return (from t in source
                    orderby t.Article descending
                    select t).ToList();
        }
        private IEnumerable<Models.Product> getByPriceAscending(IEnumerable<Product> source)
        {
            return (from t in source
                    orderby t.Price ascending
                    select t).ToList();
        }
        private IEnumerable<Models.Product> getByPriceDescending(IEnumerable<Product> source)
        {
            return (from t in source
                    orderby t.Price descending
                    select t).ToList();
        }
        private IEnumerable<Models.Product> getByDateAscending(IEnumerable<Product> source)
        {
            return (from t in source
                    orderby t.DateOfChange ascending
                    select t).ToList();
        }
        private IEnumerable<Models.Product> getByDateDescending(IEnumerable<Product> source)
        {
            return (from t in source
                    orderby t.DateOfChange descending
                    select t).ToList();
        }
    }
}
